package com.enjoy.sentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.enjoy.sentinel.common.CommonException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {

    @RequestMapping("user")
//    @SentinelResource(value = "user")
    @SentinelResource(value = "user", blockHandler = "exceptionHandler", blockHandlerClass = CommonException.class)
    public String getUserInfo() {

        return "success userinfo";
    }

    // Fallback 函数，函数签名与原函数一致或加一个 Throwable 类型的参数.
//    public String helloFallback(long s) {
//        return String.format("hello %d", s);
//    }

    // Block 异常处理函数，参数最后多一个 BlockException，其余与原函数一致.
//    public String exceptionHandler(int s, BlockException ex) {
//        // Do some log here.
//        ex.printStackTrace();
//        return "Oops, error occurred at " + s;
//    }
}
